# -*- coding: utf-8 -*- 
# @Time : 2022/7/18 21:25 
# @Author : johnforrest 
# @File : removewatermarker.py


# from PIL import Image
from itertools import product
import fitz
import os


def remove_pdf():
    page_num = 0
    # pdf_file = input("请输入 pdf 地址：")
    # pdf = fitz.open(pdf_file);
    pdf = fitz.open("F:\\项目管理师\\01.鲜知备考宝典《综合知识》一本通.pdf")
    for page in pdf:
        pixmap = page.get_pixmap()
        for pos in product(range(pixmap.width), range(pixmap.height)):
            rgb = pixmap.pixel(pos[0], pos[1])
            if(sum(rgb) >= 620):
                pixmap.set_pixel(pos[0], pos[1], (255, 255, 255))
        pixmap.pil_save(f"d:/pdf_images/{page_num}.png")
        print(f"第{page_num}水印去除完成")
        page_num = page_num + 1

if __name__ == '__main__':
    remove_pdf()

